import java.util.Arrays;
import java.util.Random;

class Solution {
    public int[] inventoryManagement(int[] stock, int cnt) {
        qsort(stock, 0, stock.length - 1);
        int [] retult = Arrays.copyOfRange(stock,0,cnt);
        return retult;
    }
    public void qsort(int[] nums, int l, int r) {
        if (l >= r) return;
        int x = nums[new Random().nextInt(r - l + 1) + l];
        int i = l;
        int left = l - 1, right = r + 1;
        while (i < right) {
            if (nums[i] < x) {
                swap(nums, ++left, i++);
            } else if (nums[i] == x) {
                i++;
            } else {
                swap(nums, --right, i);
            }
        }
        qsort(nums, l, left);
        qsort(nums, right, r);
    }
    public void swap(int[] nums, int a, int b) {
        int t = nums[a];
        nums[a] = nums[b];
        nums[b] = t;
    }
}